home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / EasyPLUGINs / source / icongad.e < prev    next >
Encoding:
Text File  |  1998-02-08  |  4.1 KB  |  160 lines

  1. /*
  2. **
  3. ** $VER: IconGad PLUGIN V1.10 (08-Feb-98) - By Fabio Rotondo
  4. **
  5. ** Name         : IconGad PLUGIN
  6. **
  7. ** Copyright    :
  8. ** EMail        : fsoft@intercom.it
  9. ** WWW          : http://www.intercom.it/~fsoft
  10. **
  11. ** ProgID       : $01
  12. ** ProgrammerID : $03
  13. **
  14. ** Version      : 1.10
  15. ** Date         : 01-Feb-98
  16. **
  17. ** Notes        : Fixed AND enhanced by:  Jason Hulance (jason@fsel.com)
  18. **                Comments between /* */ are mine (Fabio)
  19. **                Comments satrting with -> are from Jason
  20. **
  21. **
  22. ** History      : 1.00  - Inital Release
  23. **
  24. **                1.10  - Now it is (I hope) EasyPLUGINs StyleGuide Compliant :-)
  25. **
  26. **                      - Added ICONGAD constant TO use instead of PLUGIN one in your
  27. **                        interfaces.
  28. **
  29. **                      - Added the disabled() method.
  30. */
  31.  
  32.  
  33. OPT OSVERSION=37
  34. OPT MODULE
  35. OPT EXPORT
  36.  
  37.  
  38. MODULE  'workbench/workbench',
  39.         'exec/ports',
  40.         'icon',
  41.         'intuition/screens', 'intuition/intuition',
  42.         'gadtools', 'libraries/gadtools',
  43.         'tools/easygui', 'tools/Exceptions'
  44.  
  45.  
  46. CONST ICONGAD_BASE = $83010000
  47.  
  48. CONST ICONGAD      = PLUGIN
  49.  
  50.  
  51. /* 
  52.    This is our new plugin. 
  53.    Note the PRIVATE keyword: 
  54.    we don't want the user to access these fields.
  55. */
  56.     
  57. OBJECT icongad_plugin OF plugin
  58.   PRIVATE
  59.   dobj:PTR TO diskobject
  60. -> Have our own gadget (don't use dobj's gadget)
  61.   gad:PTR TO gadget
  62.   disabled
  63. ENDOBJECT
  64.  
  65. /*
  66.     This is the init proc for the plugin.
  67.     You must provide a valid icon name (full path)
  68.     without the ".info" extension (it is added automagically
  69.     by GetDiskObject() call)
  70. */
  71. PROC init(fname) OF icongad_plugin
  72.   IF (iconbase:=OpenLibrary('icon.library', 0))=NIL THEN Raise("ilib")
  73.   self.dobj := GetDiskObject(fname)
  74.   IF self.dobj = NIL THEN Raise("icon")
  75.  
  76. -> Copy the relevant parts of dobj to our gadget
  77. -> The *vital* part is the initialisation of the "activation" field to
  78. -> a known value (GACT_RELVERIFY).  That way, we know what IDCMP messages
  79. -> the gadget will generate.
  80.  
  81.   self.gad:=NEW [NIL, 0, 0, self.dobj.gadget.width, self.dobj.gadget.height,
  82.                  self.dobj.gadget.flags, GACT_RELVERIFY,
  83.                  self.dobj.gadget.gadgettype,
  84.                  self.dobj.gadget.gadgetrender,
  85.                  self.dobj.gadget.selectrender,
  86.                  NIL, 0, NIL, 0, NIL]:gadget
  87. ENDPROC
  88.  
  89. /*
  90.    We free all Alloc()ed resources.
  91.    Remeber to always END your PLUGINs before program termination.
  92. */
  93. PROC end() OF icongad_plugin
  94.   IF self.dobj THEN FreeDiskObject(self.dobj)
  95.   IF iconbase THEN CloseLibrary(iconbase)
  96.   END self.gad
  97. ENDPROC
  98.  
  99. /* The icon cannot be stretched, so it cannot be resized... */
  100. PROC will_resize() OF icongad_plugin IS FALSE
  101.  
  102.  
  103. /* We provide, as min size, the Icon size */
  104. PROC min_size(ta, fh) OF icongad_plugin IS self.gad.width, self.gad.height
  105.  
  106.  
  107. /* This is the render proc */
  108. PROC render(ta, x,y, xs, ys, win:PTR TO window) OF icongad_plugin
  109.   IF self.gh    = NIL THEN RETURN
  110.   IF win        = NIL THEN RETURN
  111.  
  112.   IF self.gad
  113.     self.gad.leftedge:=x
  114.     self.gad.topedge :=y
  115.     AddGadget(win, self.gad, NIL)
  116. -> The final argument to RefreshGList() ought to be 1, not 0
  117.     RefreshGList(self.gad, win, NIL, 1)
  118.  
  119.     self.change_status(win)
  120.   ENDIF
  121. ENDPROC
  122.  
  123. PROC change_status(win) OF icongad_plugin
  124.   IF self.disabled
  125.     OffGadget(self.gad, win, NIL)
  126.   ELSE
  127.     OnGadget(self.gad, win, NIL)
  128.   ENDIF
  129. ENDPROC
  130.  
  131.  
  132. /* 
  133.     And here there is the clear proc 
  134.     Since we have created a standard gadget, we simply
  135.     remove it from the gadget list of the window.
  136. */
  137. PROC clear_render(win:PTR TO window) OF icongad_plugin
  138.   IF self.gad THEN IF win THEN RemoveGadget(win, self.gad)
  139. ENDPROC
  140.  
  141. PROC message_test(imsg:PTR TO intuimessage, win:PTR TO window) OF icongad_plugin
  142. -> Because we set the gadget's activation field we know we'll only get
  143. -> IDCMP_GADGETUP generated by our gadget.
  144.   IF (imsg.class=IDCMP_GADGETUP) THEN RETURN imsg.iaddress=self.gad
  145. ENDPROC FALSE
  146.  
  147. PROC message_action(a,b,c,d) OF icongad_plugin IS TRUE
  148.  
  149. PROC disabled(dis=TRUE) OF icongad_plugin
  150.   IF dis<>self.disabled
  151.     self.disabled:=dis
  152.  
  153.     IF self.gh     = NIL THEN RETURN
  154.     IF self.gh.wnd = NIL THEN RETURN
  155.  
  156.     self.change_status(self.gh.wnd)
  157.   ENDIF
  158. ENDPROC
  159.  
  160.